    function getTodayDate()
    {
        var date = new Date();
        var dateStr = date.format("yyyy-MM-dd");
        return dateStr;
    }

    function saveTurnover(type)
    {
        var typeStr = getTypeStr(type);
        var money = $("#money" + typeStr).val();
        var cat = $("#category" + typeStr).val();
        var from = 0;
        var to = 0;
        if(type == 0)
        {
            from = $("#account" + typeStr).val();
        } else if(type == 1)
        {
            to = $("#account" + typeStr).val();
        } else if(type == 2)
        {
            from = $("#account" + typeStr + "from").val();
            to = $("#account" + typeStr + "to").val();
        }
        
        var date = $("#date" + typeStr).val();
        var remark = $("#remark" + typeStr).val();
        var turnover = new Turnover(0,money,remark,from,to,date,type,cat);
        turnover.Add();
        window.location.href='index.html'; 
     
     
        
    }
    function getTypeStr(type)
    {
        typeStr = "";
        if(type == 0)
        {
            typeStr = "outgo";
        } else if(type == 1)
        {
            typeStr = "income";
        } else if(type == 2)
        {
            typeStr = "transfer"
        }
        return typeStr;
    }
    $(document).ready(function(){
        InitAddTurnover();
    });//文档已经准备好了，可以调用JS
    function InitAddTurnover()
    {
        
        datamodel.init();
        ///////////////////////////////////////////////////////////////
        for(var type = 0; type <= 2; ++ type)
        {
            ///////////////////////////////////////////////////////////////
            var typeStr = getTypeStr(type);
            var accountselectid = "#account";
                accountselectid += typeStr;

                for(var accountid in datamodel.accounts)
                {
                    var account = datamodel.accounts[accountid];
                    var oneSelect = "<option value='{0}'>{1}</option>"
                    oneSelect = oneSelect.format(account.id,account.name);
                    if(type == 2)
                    {
                        $(accountselectid + "from").append(oneSelect);
                        $(accountselectid + "to").append(oneSelect);
                    } else 
                    {
                        $(accountselectid).append(oneSelect);
                    }
                    
                }
                
            ///////////////////////////////////////////////////////////////    
            if(type != 2)
            {
                 //生成类别选择框
                    var categoryselectid = "#category";
                    categoryselectid += typeStr;

                    for(var categoryid in datamodel.categorys)
                    {
                        var category = datamodel.categorys[categoryid];
                        if(category.type == type)
                        {
                            var oneSelect = "<option value='{0}'>{1}</option>"
                            oneSelect = oneSelect.format(category.id,category.name);
                            $(categoryselectid).append(oneSelect);
                        }
                        
                    }
            }
             ///////////////////////////////////////////////////////////////

            $("#date" + typeStr).val(getTodayDate());

            
        }
        ///////////////////////////////////////////////////////////////
                
                
       
        
        
        
        
       // alert("InitAddTurnover");
         //   var datamodel = new DataModel();
        
   /*
          var typeStr = "";

           typeStr = getTypeStr(type);
            
            setTodayDate(typeStr);
            ///////////////////////////////////////////////////////////////////////

           
            

                
                
                $("#save" + typeStr).click(function(){
                    saveTurnover(type);
                })
    */
    }